import { Table, Tabs } from 'antd';
import React, { useEffect, useState } from 'react'
import TableComponent from './TableTableComponent';
import AddAdmin from './AddAdmin';
import styes from '../index.module.scss'
import { getAdminApi } from '@/common/api';
export default function Admin() {
  const [adminDataSource, setAdminDataSource] = useState([])
  useEffect(() => {
    getAdminFn()
  }, [])
  const getAdminFn = async() => {
    const RES = await getAdminApi()
    if (RES.code === 200) {
      setAdminDataSource(RES.data)
    }
  }
  const items = [
    {
      key: '1',
      label: '管理员列表',
      children: <TableComponent adminDataSource={ adminDataSource} />,
    },
    {
      key: '2',
      label: '添加管理员',
      children: <AddAdmin setAdminDataSource={(value)=>setAdminDataSource(pre=>[...pre,value])} />,
    }
  ];
  return (
    <div className={ styes.admin}>
      <Tabs defaultActiveKey="1" items={items}/>;
    </div>
  )
}
